$(function () {
  function Pop(msg) {
    $(".pop p").html(msg);
    $(".pop").fadeIn();
    var time = 2;
    setInterval(() => {
      if (time == 0) {
        $(".pop").fadeOut();
      } else {
        time--;
      }
    }, 1000);
  }

  // 下拉框
  $(".slide")
    .children(".arrow-icon")
    .hover(function () {
      $(this).children("ul").stop().slideToggle("fast");
    });

  // 登录信息获取
  var ul = document.querySelector(".shortcut .fl>ul");
  var wel = $(".shortcut .fl>ul>li>a");
  var username = localStorage.getItem("nowUser");
  if (username != null) {
    wel[0].innerText = "欢迎您";
    wel[1].innerText = username;
    var del = document.createElement("li");
    del.innerText = "退出";
    del.setAttribute("style", "margin-left: 5px; cursor: pointer;");
    del.className = "style_red";
    del.addEventListener("click", function () {
      localStorage.removeItem("nowUser");
      wel[0].innerText = "请登录";
      wel[1].innerText = "免费注册";
      document.location.href = "index.html";
      this.remove();
    });
    ul.appendChild(del);
  } else {
    wel[0].innerText = "请登录";
    wel[1].innerText = "免费注册";
  }

  // 跳转检查
  $(".logined")
    .children("li")
    .click(function (event) {
      var username = localStorage.getItem("nowUser");
      if (username == null) {
        event.preventDefault();
        Pop("请您先登录");
      }
    });
});
